/**
 * /**
 * issue list
 * @type {issue_list}
 */
var issue_list = function () {
    var grid_id = 'issue_list';
    var info;
    var toolbar = $('#issue_toolbar').toolbar();
	//全局变量表示是单选issue 还是多选issue （0表示多选）
	var ids_post = null;
	//全局变量表示当前单操作的问题id
	var currentId;
    var $issue_grid;
	var editor =null;
	var fix_editor=null;
    //判断是否显示列表的checkbox
    var bool_show_checkbox;
    //判断是否显示列表的checkbox
    var bool_show_checkbox;
    /**
     * 选中tab的 cookie名称
     * @type {string}  cookie名称
     */
    var select_tab_cookie_name = 'select_tab_cookie';
    /* 选中b_assign 按钮的cookie名称
     * @type {String}
     */
	var select_assign_cookie_name = 'b_assign_cookie';

    /** tab 标签取值*/
    var tab_value={todo:"todo",done:"done",all:"all",my_issue:"my_issue"};
    /**用于b_assign按钮的变量*/
    var cookie_filter = { me : 'assign_to_me', all: 'all_my_issue' };
    /**用与fix按钮的变量*/
    var fix_value={ fixed:'fixed',all:'f_all' };

    //默认显示全部问题，所以显示fixed按钮      全局变量
    var fix_temp=fix_value.fixed;
    /*操作列按钮列表*/
    var operation_icon=[
        {id:"close",icon_url:"/close.png",description:language.issue.close_text},
        {id:"assign",icon_url:"/assigned.png",description:language.issue.column_3},
        {id:"label",icon_url:"/label.png",description:language.issue.list_toolbar_text.label},
        {id:"priority",icon_url:"/priority.png",description:language.issue.list_toolbar_text.prioperty},
        {id:"undo",icon_url:"/undo.png",description:language.issue.list_toolbar_text.reopen},
        {id:"fix",icon_url:"/fix.png",description:language.issue.fix_text}
         ];
    /**
     *     grid列表显示的所有列定义
     * @type {Array}
     */
      var columnsDatascource;
	/**
     * 左边工具条
     * @type {Array} 工具条信息，包含todo等的定义
     */
    var tool_bar_datasource = [
        {key: tab_value.todo, values: [
            {id: "issue_close", text: language.issue.list_toolbar_text.close, icon: "closed", onclick: "issue_list.close('0')", tooltip: language.issue.list_tool_tip_msg.close, disabled: "true"},
            {id: "issue_assign", text: language.issue.list_toolbar_text.assign, icon: "assigned", onclick: "issue_list.team_account()", tooltip: language.issue.list_tool_tip_msg.assign, disabled: "true"},
			{id: "issue_label_change", text: language.issue.list_toolbar_text.label, icon: "label", onclick: "issue_list.label_change_div(0)", tooltip: language.issue.list_tool_tip_msg.label, disabled: "true"},
			{id: "issue_priopity_change", text: language.issue.list_toolbar_text.prioperty, icon: "priority", onclick: "issue_list.priopity_layer(0)", tooltip: language.issue.list_tool_tip_msg.prioperty, disabled: "true"}
             ]},
        {key: tab_value.done, values: [
			{id: "issue_reopen", text: language.issue.list_toolbar_text.reopen, icon: "undo", onclick: "issue_list.reopen_issues(0)", tooltip: language.issue.list_tool_tip_msg.reopen, disabled: "true"}
		]},
       {key: tab_value.all, values: [
         ]},
        {key: tab_value.my_issue, values: [
         ]}
    ];
	var r_button_datascource = [
		{id: cookie_filter.me, text: language.issue.list_toolbar_text.assign_to_me, icon: "assignme", onclick: "issue_list.b_assign_switch()", tooltip: language.issue.list_tool_tip_msg.assign_to_me, disabled: "false"},
		{id: cookie_filter.all, text: language.issue.list_toolbar_text.all, icon: "allissues", onclick: "issue_list.b_assign_switch()", tooltip: language.issue.list_tool_tip_msg.all, disabled: "false"},
        {id: fix_value.fixed, text: language.issue.list_toolbar_text.fixed, icon: "fixed", onclick: "issue_list.b_fix_switch()", tooltip: language.issue.list_tool_tip_msg.fixed, disabled: "false"},
        {id: fix_value.all, text: language.issue.list_toolbar_text.all_with_fix, icon: "fix_all", onclick: "issue_list.b_fix_switch()", tooltip: language.issue.list_tool_tip_msg.all_with_fixed, disabled: "false"}
    ];
    var format_str = {
        key_format            : '<a href="view/{0}">{0}</a>', summary_format: '<a href="view/{0}">{1}</a>',
        type_format           : '<a href="view/{0}"><img src="' + js_param.image_url + '/{1}" class="icon" title="{2}" alt="{3}" height="16" width="16" border="0"/></a>',
        priopity_format       : '<a href="view/{0}"><img src="' + js_param.image_url + '/{1}"class="icon"title="{2}" alt="{3}"height="13" width="14" border="0"/>{2}</a> ',
        operation_close_format: '<a href="javascript:;"onclick="issue_list. close({0})"><img src="' + js_param.image_url +operation_icon[0].icon_url+'"title="'+operation_icon[0].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
                                                    '<a href="javascript:;" onclick="issue_list.single_assign({0},{4})"><img src="' + js_param.image_url +operation_icon[1].icon_url+'"title="'+operation_icon[1].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
                                                    '<a href="javascript:;"onclick="issue_list.label_change_div({0})"><img src="' + js_param.image_url +operation_icon[2].icon_url+'"title="'+operation_icon[2].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
                                                    '<a href="javascript:;"onclick="issue_list. priopity_layer({0})"><img src="' + js_param.image_url +operation_icon[3].icon_url+'"title="'+operation_icon[3].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' ,
        operation_fix_format:    '<a href="javascript:;"onclick="issue_list. fixed({0})"><img src="' + js_param.image_url +operation_icon[5].icon_url+'"title="'+operation_icon[5].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;',
        operation_space_format: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
         operation_open_format : '<a href="javascript:;" onclick="issue_list. reopen_issues({0})"><img src="' + js_param.image_url +operation_icon[4].icon_url+'"title="'+operation_icon[4].description+'"height="16" width="16" border="0"/></a>'

    };
    var assign_layer = $('#assign_account').layer({singleton: true, width: "200px", height: "220px", title: language.issue.issue_assign_title});
    var single_assign_layer_operation = $('#single_assign').layer({singleton: true, width: 150, height: 200, title: language.issue.issue_assign_title});
    var close_comment_layer = $("#issue_close_comment_back").layer({title : language.issue.issue_colse_comment,width : "550px",height : "350px",singleton: true});
    var fix_comment_layer = $("#issue_fix_comment_back").layer({title : language.issue.issue_colse_comment,width : "550px",height : "350px",singleton: true});

    var cleanup = function () {
        //清理Cookie
        $.cookie(select_tab_cookie_name, null);
        $.cookie(select_assign_cookie_name,null);
        cdms.common.clear_grid_page_cookie(grid_id);
        //清理后，修改瞄点，防止下次无法记住cookie的问题
        window.location.hash = 'local';
    };
    return {
        /**
         * 初始化Tab控件
         */
        init_tab      : function () {
            //是否存在瞄点
            var newClear = window.location.hash;
            if (newClear) {
                var action = newClear.split('#')[1];
                switch (action) {
                    case  "todo":
                        cleanup();
                        //$.cookie(select_assign_cookie_name, cookie_filter.all, { expires: 1 });
                        break;
                    case "assignee_me":
                       cleanup();
                       $.cookie(select_tab_cookie_name,tab_value.my_issue, { expires: 1 });
                        break;
                    default :
                        break;
                }
            }
            var tab = $('#issue_tab').tab();
            tab.event('select', function (item) {
                issue_list.tab_select_evt(item);
            });
            //初始化b_assign的cookie，如果没有b_assign的cookie,默认b_assign为  all
            if(!$.cookie(select_assign_cookie_name)){
                $.cookie(select_assign_cookie_name, cookie_filter.all, { expires: 1 });
            }
            //上次选中的Tab
            var select_tab_name = $.cookie(select_tab_cookie_name);
            var select_tab;
            if (!select_tab_name) {

		        //如果以前tab没有选中，则用默认地一个  (第一个)
                select_tab = tab.items(0);
            } else {
                select_tab = tab.getItemById(select_tab_name);
            }
            issue_list.tab_select(select_tab.attr('id'));
            select_tab.attr("selected", "true");
            //toolbar   右边按钮处理
            issue_list.display_rlitem();
        },
        tab_select_evt: function (tab_item) {
            cdms.common.clear_grid_page_cookie(grid_id);
            var tab_id = tab_item.item.attr('id');
            issue_list.tab_select(tab_id);
        },
        /**
         * 对Tab进行处理，包含数据的渲染
         * @param tab_id tab选项卡ID
         */
        tab_select    : function (tab_id) {
            $('#issue_p_select').attr("value", "");
            //设置工具条
            $.each(tool_bar_datasource, function (idx, val) {
                if (val.key == tab_id) {
                    toolbar.attr("dataSource", [val.values]);
                    return false;
                }
            });

            var label_div = $('#label_change_div');
            label_div.removeClass();
            var priopity_div = $('#priopity_change_div_list');
            priopity_div.removeClass();
            label_div.hide();
            priopity_div.hide();
            if (tab_id == tab_value.todo) {
                label_div.addClass("label_change_div_1");
                priopity_div.addClass("priopity_change_div_1");
            } else if (tab_id == tab_value.done) {
                label_div.addClass("label_change_div_2");
                priopity_div.addClass("priopity_change_div_2");
            } else if (tab_id == tab_value.all) {
                label_div.addClass("label_change_div_3");
                priopity_div.addClass("priopity_change_div_3");

			} else{
              label_div.addClass("label_change_div_3");
                priopity_div.addClass("priopity_change_div_3");
            }
            $.cookie(select_tab_cookie_name, tab_id, {expires: 1});
            //toolbar   右边按钮处理
            issue_list.display_rlitem();
            //得到分页前设置showCheckbox值
            issue_list.set_bool_show_checkbox();
            issue_list.display_filter();
            //表格加载，通过两个cookie变量过滤
            issue_list.list({label: tab_id, b_assign: $.cookie(select_assign_cookie_name),fix:null});
        },
        //显示前的  页面显示项目  条件过滤设置
        display_filter:         function(){
            columnsDatascource=
                [
                    [
                        {title: "T", field: "issuetype", width: "30px", headAlign: 'center', align: 'center', formatter: issue_list.type_formatter, sortfield: "issuetype"},
                        {title: "key", field: "pkey", width: "120px", headAlign: 'left', formatter: issue_list.pkeyFormatter, sortfield: "pkey"},
                        {title: language.issue.column_1, field: "summary", headAlign: 'left', formatter: issue_list.titleFormatter},
                        {title: language.issue.column_6, field: "priopity", width: "60px", headAlign: 'left', align: "left", sortfield: "priopity", formatter: issue_list.priopityFormatter},
                        {title: language.issue.column_2, field: "reporter", width: "100px", headAlign: 'left'},
                        {title: language.issue.column_3, field: "assigneeName", width: "100px", headAlign: 'left'},
                        {title: language.issue.column_4, field: "created", width: "150px", headAlign: 'left', sortfield: "created"},
                        {title: language.common.operation, field: "operation", width: "170px", align: 'center', formatter: issue_list.operationFormatter}
                    ]
                ];
                 bool_show_checkbox=true;
                if($.cookie(select_tab_cookie_name)==tab_value.all||$.cookie(select_tab_cookie_name)==tab_value.my_issue){
                    /**设置  columnsDatascource    移除operation列项*/
                    columnsDatascource[0].splice(7,1);
                    /**设置 checkbox是否显示   false为不显示*/
                    bool_show_checkbox=false;
                }
           },

        /**
         * b_assign按钮开关切换
         */
        b_assign_switch: function () {
            //清空 page  cookie
            cdms.common.clear_grid_page_cookie(grid_id);
            $.cookie(select_assign_cookie_name, ($.cookie(select_assign_cookie_name) == cookie_filter.all) ? cookie_filter.me : cookie_filter.all, { expires: 1 });
             //显示之前把相对应的另一个按钮置为  显示所有问题
              fix_temp=fix_value.fixed;
            issue_list.display_rlitem();
            //得到分页前设置showCheckbox值
            issue_list.set_bool_show_checkbox();
            issue_list.display_filter();
            //修改b_assign  cookie值
			issue_list.list({label: $.cookie(select_tab_cookie_name), b_assign: $.cookie(select_assign_cookie_name),fix:null});
        },

        /**
         * fix按钮开关切换
         */
           b_fix_switch:function(){
                //保存现在的fix值，再进行切换
              var fix=fix_temp;
            //开关切换
            fix_temp= (fix_temp==fix_value.fixed?fix_value.all:fix_value.fixed);
            //显示之前把相对应的另一个按钮置为  显示所有问题
            $.cookie(select_assign_cookie_name,cookie_filter.all);
            issue_list.display_rlitem();
            //显示前的  页面显示项目  条件过滤设置
            issue_list.display_filter();
            issue_list.list({label: $.cookie(select_tab_cookie_name), b_assign: $.cookie(select_assign_cookie_name),fix:fix});
        },

        /**
         *  toolbar 右边按钮显示处理
         */
        display_rlitem : function () {
            //如果是  my_issue就不显示右按钮
            if($.cookie(select_tab_cookie_name)!= tab_value.my_issue){
                var b_assign = $.cookie(select_assign_cookie_name);
                toolbar.ritems(0) != null ? toolbar.ritems(0).remove() : null;
                toolbar.insertRight(r_button_datascource[b_assign == cookie_filter.me ? 1 : 0], 0);
                //  为todo时显示fix
                if($.cookie(select_tab_cookie_name)== tab_value.todo){
                    //如果是第一个标签，在右位置1加入按钮。  而且默认是显示全部。
                    toolbar.ritems(1) != null ? toolbar.ritems(1).remove() : null;
                    toolbar.insertRight(r_button_datascource[fix_temp == fix_value.fixed ? 2 : 3], 1);
                  }
                }
        },

        /**
         * list show
         */
        list                  : function (params) {
            $issue_grid = cdms.common.jart_grid(grid_id, {
		        	sortField: 'created', url: "list.json", idFields: 'id', gridline: 'horizontal', queryParams: params,showCheckBox : bool_show_checkbox,
			   columns  : columnsDatascource,
            //选中触发事件
                onCheck  : function () {
                    issue_list.toolbar_disabled_check();
               },
            //更新列表触发事件
                onUpdate  : function () {
                    issue_list.toolbar_disabled_check();
                }
            });
        },
        /**
         * checkRows  disabled操作函数
         */
        toolbar_disabled_check: function () {
            var rows = $('#' + grid_id).grid("checkedRows");
            for (var i = 0; i <toolbar.attr("dataSource")[0].length; i++) {
                toolbar.litems(i).attr('disabled', rows.length == 0);
            }
        },
        /**
         *  通过tab的cookie值来控制 checkbox是否显示
         */
        set_bool_show_checkbox:function(){
            bool_show_checkbox = ($.cookie(select_tab_cookie_name)==tab_value.todo||$.cookie(select_tab_cookie_name)==tab_value.done? true : false);
        },
        pkeyFormatter : function (item) {
            return format_str.key_format.format(item.pkey);
        },
        titleFormatter: function (item) {
            return format_str.summary_format.format(item.pkey, item.summary);
        },

        priopityFormatter: function (item) {
            var priopity = {};

            $.each(priopity_list, function (idx, val) {

                if (val.id == item.priopity) {
                    priopity = val;
                    return false;
                }
            });
            return  format_str.priopity_format.format(item.pkey, priopity.iconUrl, priopity.description, priopity.name);
        },
        type_formatter   : function (item) {
            var type = {};
            $.each(type_list, function (idx, val) {
                if (val.id == item.issuetype) {
                    type = val;
                    return false;
                }
            });
            return  format_str.type_format.format(item.pkey, type.icon, type.description, type.pname)
        },

        /**
         * Reopen   one or more issues those been closed
         *
         */
        reopen_issues        : function (id) {
            ids_post=(id==0?cdms.common.grid_select_ids(grid_id):id );
            cdms.common.confirm(language.issue.reopen_tip_msg, function () {

                cdms.common.ajax_get('reopen/' + ids_post, issue_list.reload);
                issue_list.toolbar_disabled_check();
                $('#' + grid_id).grid().loadData();
            });

        },
        /**
         * format the hyper link of operation
         * @param item
         * @return {*}
         */
        operationFormatter   : function (item) {
			switch (item.issuestatus) {
				case 1:
                    return   format_str.operation_open_format.format(item.id, item.summary);
                    break;
                case 2:
                    return   (format_str.operation_close_format.format(item.id, item.summary, item.reporter, item.priopity, item.pid)+format_str.operation_space_format.format());
                    break;
                case 0 :
					return (format_str.operation_close_format.format(item.id, item.summary, item.reporter, item.priopity, item.pid)+format_str.operation_fix_format.format(item.id));
					break;
                default : ;
            }
        },
        /**
         * 打开快捷回复窗口
         * @param str
         */
        show_reply_layer     : function (str) {
            var str_list = str.split(",");
            $('#issue_comment_id').val(str_list[0]);
            $('#issue_comment_back').layer({"width": 630, "height": 400, "title": language.issue.quick_reply_title, "movable": true}).open();
            editor = KindEditor.create('#txt_answner', {
                themeType            : 'default',
                resizeType           : 0,
                urlType              : 'domain',
                shadowMode           : false,
                allowPreviewEmoticons: false,
                allowImageUpload     : true,
                allowFlashUpload     : false,
                uploadJson           : js_param.upload_url,
                afterCreate          : function () {
                    KindEditor.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
                        $("#txt_answner").parent().submit();
                    });
                },
                afterChange          : function () {
                    this.sync();
                },
                items                : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'insertorderedlist', 'insertunorderedlist',
                    'forecolor', 'hilitecolor', 'fontname', 'fontsize', '|', 'link', 'unlink', 'image', 'flash', 'quote', '|', 'source', 'about']
            });
            var priopity = "";
            var innerhtml = "<h4>" + "</br>" + language.issue.title_msg + "：" + str_list[1] + "</br>" + "</h4>"
            $('#issue_comment_summary').html(innerhtml);
        },
        /**
         *
         * 控制快捷回复提交
         */
        quick_comment_submit : function () {
            /**
             * 快捷回复
             */
            $('#form_answer').ajaxForm({
                dataType       : 'json',
                beforeSerialize: function ($form, options) {
                    editor.sync();
                },
                beforeSubmit   : function () {
                    var form_msg = $('#form_msg');
                    form_msg.html("<span class='ajax_processing'>" + language.issue.issue_comment_submit_note + "</span>");
                    if (editor.isEmpty()) {
                        $.alert(language.issue.issue_comment_empty_msg, language.note.alert_title);
                        return false;
                    }
                    form_msg.show();
                },
                success        : function (json) {
                    var form_msg = $('#form_msg');
                    if (json.type) {
                        $.alert({
                            title  : language.note.alert_title,
                            message: json.msg,
                            fnOk   : function () {
                                $('#issue_comment_back').layer().close();
                                editor.html("");
                            }
                        });
                    } else {
                        form_msg.html("<span class='error_msg'>" + json.msg + "</span>");
                        form_msg.show();
                    }
                }
            });
            $('#form_answer').submit();
        },
        /**
		 * Quick comment when user batch close question
		 * 
		 */
		close_comment_submit : function(){
					var form_msg = $('#close_form_msg');
					form_msg.html("<span class='ajax_processing'>" + language.issue.issue_comment_submit_note + "</span>");
					if (editor.isEmpty()) {
						$.alert(language.issue.issue_comment_empty_msg, language.note.alert_title);
						return false;
					}
					form_msg.show();
					var params = {'ids':ids_post,'content':editor.html()};
					/**
					 * ajax_post 提交回复信息
					 * @parma params json格式参数 包含问题id列表和回复信息
					 * 成功返回后修改提示信息，关闭弹出层
					 */
					cdms.common.ajax_post(js_param.close_comment_submit_url,params,function(json){
						json = eval("("+json+")");
						if (json.type) {
							issue_list.toolbar_disabled_check();
							editor.html("");
							close_comment_layer.close();
							form_msg.hide();
                            issue_list.reload();
						} else {
							form_msg.html("<span class='error_msg'>" + json.msg + "</span>");
							form_msg.show();
						}
					});
		},
        /**
         * 修复问题功能函数
         * @param id
         */
        fixed :function(id){
            	fix_comment_layer.open();
            	$("#fix_issue_comment_id").attr("value",id);
            	if(fix_editor == null){
				fix_editor = KindEditor.create('#fix_txt_answner', {
					themeType            : 'default',
					resizeType           : 0,
					urlType              : 'domain',
					shadowMode           : false,
					allowPreviewEmoticons: false,
					allowImageUpload     : true,
					allowFlashUpload     : false,
					uploadJson           : js_param.upload_url,
					afterCreate          : function () {
						KindEditor.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
							$("#fix_txt_answner").parent().submit();
						});
					},
					afterChange          : function () {
						this.sync();
					},
					items                : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'insertorderedlist', 'insertunorderedlist',
						'forecolor', 'hilitecolor', 'fontname', 'fontsize', '|', 'link', 'unlink', 'image', 'flash', 'quote', '|', 'source', 'about']
				});
            	}
        },
        
        /**
         * fix 反馈提交
         * 
         */
        fix_comment_submit  : function(){   alert("1")
        	var form_msg = $('#fix_form_msg');
			form_msg.html("<span class='ajax_processing'>" + language.issue.issue_comment_submit_note + "</span>");
			
			if (fix_editor.isEmpty()) {
				$.alert(language.issue.issue_comment_empty_msg, language.note.alert_title);
				return false;
			}
			form_msg.show();
			
        	var id=$("#fix_issue_comment_id").attr("value");
        	var content=fix_editor.html();
        	var params ={id:id,content:content};
//        	cdms.common.ajax_post(js_param.fix_comment_submit_url,params,function(json){
//                alert("heeo")
//        		json = eval("("+json+")");
//        		if(json.type){
//							fix_editor.html("");
//							$('#fix_txt_answner').text("");
//							form_msg.hide();
//							fix_comment_layer.close();
//							 issue_list.toolbar_disabled_check();
//                             issue_list.reload();
//        		}else{
//        			form_msg.html("<span class='error_msg'>" + json.msg + "</span>");
//					form_msg.show();
//        		}
//        	});
        },
		/**
		 * 关闭问题操作，如果id  为0，属于批量关闭
         *
         * @param id
         */
        close                : function (id) {
            ids_post=(id==0?cdms.common.grid_select_ids(grid_id):id );
				close_comment_layer.open();
                if(editor == null){
                        editor = KindEditor.create('#close_txt_answner', {
                            themeType            : 'default',
                            resizeType           : 0,
                            urlType              : 'domain',
                            shadowMode           : false,
                            allowPreviewEmoticons: false,
                            allowImageUpload     : true,
                            allowFlashUpload     : false,
                            uploadJson           : js_param.upload_url,
                            afterCreate          : function () {
                                KindEditor.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
                                    $("#close_txt_answner").parent().submit();
                           });
                            },
                       afterChange          : function () {
                                this.sync();
                            },
                            items                : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'insertorderedlist', 'insertunorderedlist',
                                'forecolor', 'hilitecolor', 'fontname', 'fontsize', '|', 'link', 'unlink', 'image', 'flash', 'quote', '|', 'source', 'about']
                        });
                }
		},
        /**
         * 添加反馈
         */
        add                  : function () {
            window.location.href = "add";
        },
        issue_p_filter       : function () {
            var p_id = $('#issue_p_select').combobox("value");
            var params = {'p_id': p_id};
            $('#' + grid_id).grid({
                sortField  : 'created',
                sortOrder  : 'desc',
                queryParams: params,
                pageindex  : 1
            });
            issue_list.reload();
            issue_list.toolbar_disabled_check();
        },
        single_assign        : function (id, pid) {
            cdms.common.ajax_get(js_param.view_issue_accounts_url + pid, function (accounts) {
                var data = eval(accounts);
                var html = '<input id="assgin_to" type="hidden" /><input id="assgin_id" type="hidden" value=' + id + ' />' +
                    '<table id="assign_table" style="height: 80%;width: 100%;table-layout:fixed">';
                for (var i = 0; i < data.length; i++) {
                    html += '<tr style="height: 20px;margin: 2px;border: 2px solid;background-color: #f1edff;cursor: pointer" id="{0}" ><td onclick="issue_list._choose_assign(\'{1}\')"><a href="javascipt:;" style="text-decoration: none;color: #85848f; font-size: 14px ">{2}</a></td></tr>'.format(data[i].login, data[i].login, data[i].name);
                }
                html += "<tr></tr></table>";
                html += "<button id='assign' width='100%' style='float:left' onclick='issue_list.single_asssign_submit()'><span><span>{0}</span></span></button>".format(language.issue.issue_assing_confirm);
                html += "<button id='assign' width='100%' style='float:right' onclick='issue_list.close_layer(\"{0}\")'><span><span>{1}</span></span></button>".format("single_assign", language.common.cancel);

                single_assign_layer_operation.attr("contents", html);
                single_assign_layer_operation.open();

            });
        },
        _choose_assign       : function (assign) {
            $("#assign_table").find("tr[id !='" + assign + "']").css({backgroundColor: "#f1edff"});
            $("#" + assign).css({backgroundColor: "#C6A186", textDecorationColor: "white"});
            $("#assgin_to").attr("value", assign);
        },
        /**
         * 列表操作栏中的指派给操作
         * @return {boolean}
         */
        single_asssign_submit: function () {
            var assign_name = $("#assgin_to").attr("value");
            var assign_id = $("#assgin_id").attr("value");
            if (assign_name == "") {
                $.alert(language.issue.not_checked, language.note.alert_title);
                return false;
            }
            var param = {id: assign_id, name: assign_name};
            cdms.common.ajax_post(js_param.view_assign_submit, param, function (msg) {
                if (msg.type) {
                    $.alert(msg.msg, language.note.alert_title);
                    return;
                }
                single_assign_layer_operation.close();
                $('#' + grid_id).grid().loadData();
                issue_list.toolbar_disabled_check();
            });
        },
        /**
         * 工具条的指派给操作
         * @return {boolean}
         */
        asssign_submit       : function () {
            var names = "";
            var ids = "";
            for (var index = 0; index < info.length; index++) {
                if ($("#" + info[index].project_id + "_assign_name").attr("value") == "") {
                    $.alert(language.issue.not_checked, language.note.alert_title);
                    return false;
                }
                ids += $("#" + info[index].project_id + "_assign_ids").attr("value") + ",";
                names += $("#" + info[index].project_id + "_assign_name").attr("value") + ",";

            }
            var params = {ids: ids, names: names};
            cdms.common.ajax_post("assign_submit", params, function (msg) {
                if (msg.type) {
                    $.alert(msg.msg, language.note.alert_title);
                    return;
                }
                $("#assign_account").layer().close();
                issue_list.toolbar_disabled_check();
                $('#' + grid_id).grid().loadData();
            });
        },
        /**
         * Close layer
         */
        close_layer          : function (id) {
            $("#" + id).layer().close();
			if($("#close_txt_answner")!=null){
				$("#close_txt_answner").attr("value","");
			}
        },
        /**
         * assign the question to account
         */
        team_account         : function () {

            var rows = $('#' + grid_id).grid("checkedRows");
            if (rows.length == 0) {
                $.alert(language.issue.not_checked, language.note.alert_title);
                return;
            }
            var p_ids = "";
            var ids = "";
            for (var i = 0; i < rows.length; i++) {
                var rowData = rows[i].attr("data");
                if (i == rows.length - 1) {
                    p_ids += rowData.pid;
                    ids += rowData.id;
                }
                else {
                    p_ids += rowData.pid + ",";
                    ids += rowData.id + ",";
                }

            }
            var aj_parma = {p_ids: p_ids};
            cdms.common.ajax_post("assign", aj_parma, function (project_account) {
                var data = eval(project_account);
                info = data;
                var html = "<div width='auto' height='180px' style='overflow: auto;overflow-x: auto;'> ";
                var rows_check = $('#' + grid_id).grid("checkedRows");
                for (var index = 0; index < data.length; index++) {
                    var issues_ids = "";
                    for (var i = 0; i < rows_check.length; i++) {
                        var row_checkData = rows_check[i].attr("data");
                        if (row_checkData.pid == data[index].project_id) {
                            issues_ids += row_checkData.id + "-";
                        }
                    }

                    html += "<div style=' overflow:auto;'  art='panel' height='auto'  id='" + data[index].project_id + "' title='" + data[index].project_name + "'> " +
                        "<input type ='hidden' style='background-color: #808080;' readonly id='" + data[index].project_id + "_assign_name' />";
                    html += "<input type ='hidden'  id='" + data[index].project_id + "_assign_ids' value='" + issues_ids + "' />";

                    html += "<ul class='team_lsit'><table style='border-collapse: 2; height:auto' >";
                    for (var name_index = 0; name_index < data[index].project_team.length; name_index++) {
                        var login = data[index].project_team[name_index].login;
                        var name = data[index].project_team[name_index].name;
                        var pid = data[index].project_id;
                        html += '<tr  onclick="issue_list.choose_assign({0},\'{1}\');" style="cursor:pointer;  border: 2px;border-top: 3px"><td  ><li style="cursor: hand;font-size:14px;background-color:#ddddff"  id="{0}{1}" >{2}--------------({1})</li></td></tr>'
                            .format(pid, login, name);
                    }
                    html += "</table></ul></div>";
                }

                //html += '<div style="float:right;" ></div>';
                html += '<div style="clear:both; height:20px;" >';
                html += '<button id="assign"  style="float: left; bottom: 1px;right: 1px;" onclick="issue_list.asssign_submit()"><span><span>{0}</span></span></button>'.format(language.issue.issue_assing_confirm);
                html += '<button id="assign"  style="float: right; bottom: 1px;right: 1px;" onclick="issue_list.close_layer(\'{0}\')"><span><span>{1}</span></span></button>'.format("assign_account", language.common.cancel);
                html += '</div></div>';
                assign_layer.attr('contents', html);
                assign_layer.open();
            });

        },
        choose_assign        : function (p_id, name) {
            $("#" + p_id + "_assign_name").attr("value", name);
            $('#' + p_id + name).css("background-color", 'gray');
            $('#' + p_id).find("table tr td li[id !=\'{0}\']".format(p_id + name)).css("background-color", "#ddddff");
        },


        /**
         * refresh grid
         */
        reload               : function () {
            $('#' + grid_id).grid().loadData();
        },
        show_hide            : function () {
            $('#priopity_change_div_list').slideUp();
		
        },
        priopity_show_hide   : function () {
            $('#label_change_div').slideUp();
            if ($('#priopity_change_div_list').css("display") == "none") {
                $('#priopity_change_div_list').slideDown();
            }
            else
                $('#priopity_change_div_list').slideUp();
        },
        all_hide             : function (e) {
            if ($.browser.firefox) {
                var wx = e.clientX;
                var wy = e.clientY;
            } else {
                var wx = window.event.clientX;
                var wy = window.event.clientY;
            }
    		var label_left = $('#label_change_div').offset().left;
			var label_top = $('#label_change_div').offset().top;
			var d_width = $('#label_change_div').width();
			var d_height = $('#label_change_div').height();
            if (wx < label_left || wy < label_top || wx > (label_left + d_width) || wy > (label_top + d_height)) {
                $('#label_change_div').slideUp();
            }
			var d_left = $('#priopity_change_div_list').offset().left;
			var d_top = $('#priopity_change_div_list').offset().top;
			var d_width = $('#priopity_change_div_list').width();
			var d_height = $('#priopity_change_div_list').height();
           if (wx < d_left || wy < d_top || wx > (d_left + d_width) || wy > (d_top + d_height)) {
                $('#priopity_change_div_list').slideUp();
            }
            return false;
        },
        label_f_click        : function (dom_id) {
            var current = $('#' + dom_id);
            var linek = $('#' + dom_id + '_link');
            linek.addClass("selected");
            var value = current.attr("value");
            var color = current.attr("color");
            linek.css('background', color);
            var choose_label = $("#choose_label");
            choose_label.find("li[value!='" + value + "']").removeClass("selected");
            choose_label.find("a[value!='" + value + "']").removeAttr('style');
            var val_selct = $('#label_select_val');
            val_selct.val(value);
            val_selct.attr('name', current.attr('name'));
            val_selct.attr('color', color);
        },
        priopity_f_click     : function (dom_id) {
            var current = $('#' + dom_id);
            var linek = $('#' + dom_id + '_link');
            linek.addClass("selected");
            var value = current.attr("value");
            linek.addClass("linek");
            var choose_priopity = $("#choose_priopity");
            choose_priopity.find("li[value!='" + value + "']").removeClass("selected");
            choose_priopity.find("a[value!='" + value + "']").removeAttr('style');
            choose_priopity.find("a[value!='" + value + "']").removeClass("linek");
            var val_selct = $('#priopity_select_val');
            val_selct.val(value);
            val_selct.attr('name', current.attr('name'));
        },
        choose_label_close   : function () {
			$("#label_change_div").layer().close();
        },
        choose_close         : function () {
			$('#priopity_change_div_list').layer().close();
        },
        choose_ok            : function () {
		
            var val_selct = $('#label_select_val');
            var label = val_selct.val();
            if (!label) {
                $.alert(language.issue.chose_label_msg, language.note.alert_title);
                return;
            }
            var color = val_selct.attr('color');
            var name = val_selct.attr('name');
            var rows = $('#issue_list').grid("checkedRows");
			var ids="";
			if(currentId==0){
			if (rows.length == 0) {
              $.alert(language.issue.not_checked, language.note.alert_title);
                return;
				}
				else{
					for (var i = 0; i < rows.length; i++) {
						var rowData = rows[i].attr("data");
						ids += rowData.id + ",";
					}
				}
			}
			else{
					ids=currentId;
			}
			
            cdms.common.ajax_post('label_change', {ids: ids, lv: label}, function (data) {
                issue_list.reload();
                currentId=0;
                $("#label_change_div").layer().close();

            });
        },
		label_change_div : function(id){
			currentId = id;
			$("#label_change_div").layer({
				width : "160px",
				height : "210px",
				singleton: true
			}).open();
			
        },
		priopity_layer : function(id){
			currentId = id;
			$("#priopity_change_div_list").layer({
				width : "160px",
				height : "210px",
				singleton: true
			}).open();
		},
        priopity_choose_close: function () {
			$('#priopity_change_div_list').layer().close();
        },
        priopity_choose_ok   : function () {
            var val_selct = $('#priopity_select_val');
            var priopity = val_selct.val();

            if (!priopity) {
                $.alert(language.issue.chose_prioperty_msg, language.note.alert_title);
                return;
            }
            var color = val_selct.attr('color');
            var name = val_selct.attr('name');
            var rows = $('#issue_list').grid("checkedRows");
			var ids = "";
			if(currentId==0){
				if (rows.length == 0) {
                $.alert(language.issue.not_checked, language.note.alert_title);
                return;
				}
				else{
					for (var i = 0; i < rows.length; i++) {
						var rowData = rows[i].attr("data");
						ids += rowData.id + ",";
					}
				}
			}
			else{
					ids=currentId;
			}
            cdms.common.ajax_post('priopity_change', {ids: ids, priopity: priopity}, function (data) {
                issue_list.reload();
				$("#priopity_change_div_list").layer().close();
				currentId=0;
                issue_list.toolbar_disabled_check();
            });
        }

    }
}();


$(document).ready(function () {
    //初始化type
    issue_list.init_tab();
    $(document).mousedown(function (e) {

        issue_list.all_hide(e);
    });
});

